<template>
<div class="center-bot">
  <dv-border-box-10>
    <div class="amap-wrapper">
      <el-amap v-if="show" ref="map" :vid="'amapDemo'" :viewMode="!itemsIndex ? '3D' : '2D'" :resizeEnable="true" :pitchEnable="true" :buildingAnimation="true" :pitch="!itemsIndex ? 50 : 0" :mapStyle="mapStyle" :center="center" :zoom="zoom" :plugin="plugin" :events="events">
        <el-amap-marker v-for="(item, i) in markers" :position="item.position" :key="i"></el-amap-marker>
        <el-amap-marker :position="position" :icon="icon"></el-amap-marker>
      </el-amap>
      <dv-loading v-else>加载中...</dv-loading>
    </div>
  </dv-border-box-10>
  <div class="amap-geo-wrap">
    <div class="amap-geo" :class="{'black': itemsIndex === index}" v-for="(item, index) in items" :key="index" @click="handleClickMode(index)">{{item}}</div>
  </div>
  <div class="center-bot-data" :class="{'expand': !expand}">
    <div class="bar" @click="expand = !expand">{{expand ? '〉' : '〈'}}</div>
    <person-count></person-count>
    <cover-items></cover-items>
  </div>
</div>
</template>

<script>
import PersonCount from './mapAside/PersonCount'
import CoverItems from './mapAside/CoverItems'
export default {
  name: 'CenterBot',
  components: { PersonCount, CoverItems },
  data () {
    const that = this
    return {
      expand: true,
      show: true,
      itemsIndex: 0,
      items: ['3D', '2D'],
      loaded: false,
      lng: 0,
      lat: 0,
      center: [0, 0],
      zoom: 20,
      position: [0, 0],
      icon: require('../../assets/img/ckrijun.png'),
      mapStyle: 'amap://styles/b6d7a8d8e2ed7360d7ea32b9a925d1ab',
      events: {
        init (o) {},
        zoomchange: e => {},
        zoomend: e => {},
        click: e => {
          alert('map clicked')
        }
      },
      markers: [
        {
          position: [0, 0]
        },
        {
          position: [10, 20]
        }
      ],
      // 使用其他组件
      plugin: [
        {
          pName: 'Scale',
          events: {
            init (instance) {
              console.log('Scale', instance)
            }
          }
        },
        {
          pName: 'ToolBar',
          events: {
            init (instance) {
              console.log('ToolBar', instance)
            }
          }
        },
        {
          pName: 'Geolocation',
          events: {
            init (o) {
              // o 是高德地图定位插件实例
              o.getCurrentPosition((status, result) => {
                if (result && result.position) {
                  that.lng = result.position.lng
                  that.lat = result.position.lat
                  that.center = [that.lng, that.lat]
                  that.loaded = true
                  that.$nextTick()
                }
              })
            }
          }
        }
      ]
    }
  },
  methods: {
    handleClickMode (index) {
      this.itemsIndex = index
      this.show = false
      setTimeout(() => {
        this.show = true
      }, 500)
    }
  }
}
</script>

<style lang="less">
.center-bot {
  overflow: hidden;
  margin-top: 10px;
  height: 637px;
  position: relative;
  .dv-loading {
    height: 500px !important;
  }
  .amap-geo-wrap {
    position: absolute;
    left: 14px;
    bottom: 115px;
    z-index: 9999;
    .amap-geo {
      width: 35px;
      height: 35px;
      border-top: 1px solid #ccc;
      background: #fff;
      text-align: center;
      line-height: 35px;
      &:hover {
        color: #000;
      }
    }
    .black {
      color: #000;
    }
  }
  .amap-wrapper {
    width: 100%;
    height: 100%;
    padding: 4px;
    overflow: hidden;
    border-radius: 20px;
  }
  .amap-logo, .amap-copyright{
    display: none !important;
  }
  .amap-geolocation-con {
    bottom: 60px !important;
  }

  .center-bot-data {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    .bar {
      cursor: pointer;
      position: absolute;
      width: 20px;
      height: 60px;
      left: -20px;
      top: 50%;
      margin-top: -30px;
      background: rgba(0, 0, 0, 0.5);
      border-top-left-radius: 5px;
      border-bottom-left-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: center;
      padding-left: 10px;
    }
  }
  .expand {
    right: -300px;
    .bar {
      padding-left: 0;
    }
  }
}
</style>
